using System;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Helpers;

namespace ASPNETVN.PORTAL.Modules.SECURITY
{
    public enum ModulePages
    {
        Users,
        Roles,
        Permissions,
        RoleManager
    }


    public partial class Main : PortalModuleControl
    {
        private void LoadChildControl()
        {
            const string basePath = "~/Modules/SECURITY/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page = ModulePages.Users;
            if (pageName != null)
            {
                page = (ModulePages) Enum.Parse(typeof (ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage) this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
        }

        protected void btnUser_Click(object sender, EventArgs e)
        {
            string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.Users);
            Response.Redirect(url);
        }

        protected void btnRole_Click(object sender, EventArgs e)
        {
            string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.Roles);
            Response.Redirect(url);
        }
    }
}